home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Red Shark / Missions / Mission_9 / MissionTasks.script < prev    next >
Text File  |  2001-11-13  |  14KB  |  555 lines

  1. //-------------------------------------------------------------------
  2. //
  3. //  This code is copyright 2001 by G5 Software.
  4. //  Any unauthorized usage, either in part or in whole of this code
  5. //  is strictly prohibited. Violators WILL be prosecuted to the
  6. //  maximum extent allowed by law.
  7. //
  8. //-------------------------------------------------------------------
  9.  
  10. ///////////////////////////////////
  11. //
  12. // Mission 9 -- Tank battle
  13. //
  14. //
  15.  
  16. class CM9_AIController extends CBaseAIController, CTankBattleMission_Strings, CMissionMessageColors
  17. {
  18.   boolean m_Activated_A = false;
  19.   boolean m_Activated_B = false;
  20.   boolean m_Activated_C = false;
  21.   boolean m_Activated_D = false;
  22.   boolean m_Activated_E = false;
  23.   boolean m_Activated_F = false;
  24.   boolean m_Activated_G = false;
  25.  
  26.   void OnObjectEnterArea( int _NavPointIndex, string _NavPointName, string _ObjectID)
  27.   {
  28.     Core_LogMessage("GameObject <" + _ObjectID + "> entered activate area [" + _NavPointName + "]");
  29.  
  30.     if ( !m_Activated_A
  31.       && _NavPointName == "NavPoint_Village_A"
  32.       && ( _ObjectID == "Helicopter"
  33.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  34.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_A"))))
  35.     {
  36.       Core_LogMessage(" !!! Activate A");
  37.       Core_BroadcastEvent( "OnStartAttack_A");
  38.       m_Activated_A = true;
  39.  
  40.       Core_BroadcastEvent(
  41.         "OnDisplayMessage",
  42.         m_strAttackStarted, // "Attack started"
  43.         m_BadNewsColor);
  44.     }
  45.  
  46.     if ( !m_Activated_B
  47.       && _NavPointName == "NavPoint_Village_B"
  48.       && ( _ObjectID == "Helicopter"
  49.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  50.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_B"))))
  51.     {
  52.       Core_LogMessage(" !!! Activate B");
  53.       Core_BroadcastEvent( "OnStartAttack_B");
  54.       m_Activated_B = true;
  55.     }
  56.  
  57.     if ( !m_Activated_C
  58.       && _NavPointName == "NavPoint_Village_C"
  59.       && ( _ObjectID == "Helicopter"
  60.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  61.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_C"))))
  62.     {
  63.       Core_LogMessage(" !!! Activate C");
  64.       Core_BroadcastEvent( "OnStartAttack_C");
  65.       m_Activated_C = true;
  66.     }
  67.  
  68.     if ( !m_Activated_D
  69.       && _NavPointName == "NavPoint_Village_D"
  70.       && ( _ObjectID == "Helicopter"
  71.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  72.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_D"))))
  73.     {
  74.       Core_LogMessage(" !!! Activate D");
  75.       Core_BroadcastEvent( "OnStartAttack_D");
  76.       m_Activated_D = true;
  77.     }
  78.  
  79.     if ( !m_Activated_E
  80.       && _NavPointName == "NavPoint_Village_E"
  81.       && ( (_ObjectID == "Helicopter")
  82.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  83.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_E"))))
  84.     {
  85.       Core_LogMessage(" !!! Activate E");
  86.       Core_BroadcastEvent( "OnStartAttack_E");
  87.       m_Activated_E = true;
  88.     }
  89.  
  90.     if ( !m_Activated_F
  91.       && _NavPointName == "NavPoint_F"
  92.       && ( (_ObjectID == "Helicopter")
  93.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  94.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_F"))))
  95.     {
  96.       Core_LogMessage(" !!! Activate F");
  97.       Core_BroadcastEvent( "OnStartAttack_F");
  98.       m_Activated_F = true;
  99.     }
  100.  
  101.     if ( !m_Activated_G
  102.       && _NavPointName == "NavPoint_G"
  103.       && ( (_ObjectID == "Helicopter")
  104.         || ( Core_IsStringStartsWith( _ObjectID, "Soviet")
  105.           && !Core_IsStringStartsWith( _ObjectID, "SovietTank_G"))))
  106.     {
  107.       Core_LogMessage(" !!! Activate G");
  108.       Core_BroadcastEvent( "OnStartAttack_G");
  109.       m_Activated_G = true;
  110.     }
  111.   }
  112.  
  113.   boolean m_TimerOn = false;
  114.   int m_StartTime = 0;
  115.   int m_LastMessageTime = 0;
  116.   int m_MinutesSpent = 0;
  117.  
  118.   void Init( int _GameTime)
  119.   {
  120.     m_TimerOn = true;
  121.     m_StartTime       = _GameTime;
  122.     m_LastMessageTime = _GameTime - 60000;
  123.   }
  124.  
  125.   void Update( int _GameTime)
  126.   {
  127.     if ( m_TimerOn && (_GameTime - m_LastMessageTime >= 60000))
  128.     {
  129.       m_MinutesSpent = m_MinutesSpent + 1;
  130.       m_LastMessageTime = m_LastMessageTime + 60000;
  131.  
  132.       int MinutesLeft = 11 - m_MinutesSpent;
  133.  
  134.       if ( MinutesLeft == 0)
  135.       {
  136.         Core_BroadcastEvent( "OnStartAttack_A");
  137.         m_TimerOn = false;
  138.  
  139.         Core_BroadcastEvent(
  140.           "OnDisplayMessage",
  141.           m_strAttackStarted,
  142.           m_BadNewsColor);
  143.       }
  144.       else
  145.       {
  146.         Core_BroadcastEvent(
  147.           "OnDisplayMessage",
  148.           m_strMinutesLeft_start + MinutesLeft + m_strMinutesLeft_end,
  149.           m_ReminderColor);
  150.       }
  151.     }
  152.   }
  153.  
  154.   void OnStartAttack_A()
  155.   {
  156.     m_TimerOn     = false;
  157.     m_Activated_A = true;
  158.   }
  159. }
  160.  
  161. class CM9_Attack extends CBaseAITask_BaseTask, CNavPointUser
  162. {
  163.   int      m_StartTime = 0;
  164.  
  165.   boolean  m_Wait              = true;  // initial state - wait before attack
  166.   boolean  m_MoveToDislocation = false; // move to dislocation point
  167.   boolean  m_Attack_A          = false; // final attack
  168.  
  169.   // delayed order
  170.   boolean  m_Delayed_MoveToDislocation = false;
  171.   boolean  m_Delayed_Attack_A          = false;
  172.   int      m_GiveOrderTime             = 0;
  173.  
  174.   void Init()
  175.   {
  176.     m_StartTime = GetGameTime() + int(rand(0, 10000));
  177.     SetFireStyle_NoFire();
  178.   }
  179.  
  180.   void OnUpdate()
  181.   {
  182.     if ( m_Wait && (GetGameTime() >= m_StartTime + GetActivateDelay()))
  183.     {
  184.       // activate by timer
  185.       //DoAttack();
  186.     }
  187.  
  188.     if ( m_Delayed_MoveToDislocation && (GetGameTime() >= m_GiveOrderTime))
  189.     {
  190.       GiveOrder_MoveToDislocation();
  191.     }
  192.  
  193.     if ( m_Delayed_Attack_A && (GetGameTime() >= m_GiveOrderTime))
  194.     {
  195.       GiveOrder_Attack_A();
  196.     }
  197.   }
  198.  
  199.   void ClearState()
  200.   {
  201.     m_Wait              = false;
  202.     m_MoveToDislocation = false;
  203.     m_Attack_A          = false;
  204.  
  205.     m_Delayed_MoveToDislocation = false;
  206.     m_Delayed_Attack_A          = false;
  207.     m_GiveOrderTime             = 0;
  208.   }
  209.  
  210.   void DelayedGiveOrder_MoveToDislocation()
  211.   {
  212.     if ( !m_Delayed_MoveToDislocation)
  213.     {
  214.       m_Delayed_MoveToDislocation = true;
  215.       m_Delayed_Attack_A          = false;
  216.  
  217.       m_GiveOrderTime = GetGameTime() + int(rand(0, 10000));
  218.     }
  219.   }
  220.  
  221.   void DelayedGiveOrder_Attack_A()
  222.   {
  223.     if ( !m_Delayed_Attack_A)
  224.     {
  225.       m_Delayed_MoveToDislocation = false;
  226.       m_Delayed_Attack_A          = true;
  227.  
  228.       m_GiveOrderTime = GetGameTime() + int(rand(0, 10000));
  229.     }
  230.   }
  231.  
  232.   void GiveOrder_MoveToDislocation()
  233.   {
  234.     if ( !m_MoveToDislocation)
  235.     {
  236.       ClearState();
  237.       m_MoveToDislocation = true;
  238.  
  239.       DoAction();
  240.     }
  241.   }
  242.  
  243.   void GiveOrder_Attack_A()
  244.   {
  245.     if ( !m_Attack_A)
  246.     {
  247.       ClearState();
  248.       m_Attack_A = true;
  249.  
  250.       DoAction();
  251.     }
  252.   }
  253.  
  254.   string OnGetDebugInfo()
  255.   {
  256.     if ( m_Wait)
  257.       return "= wait";
  258.     if ( m_MoveToDislocation)
  259.       return " = dislocating";
  260.     if ( m_Attack_A)
  261.       return " = Attack_A";
  262.     
  263.     return "";
  264.   }
  265.  
  266.   void DoAction()
  267.   {
  268.     string NearestEnemy = GetTargetedEnemy();
  269.  
  270.     if ( NearestEnemy == "")
  271.     {
  272.       NearestEnemy = GetNearestEnemyUnit_Ranged(1000.0);
  273.     };
  274.  
  275.     if ( NearestEnemy == "")
  276.     {
  277.       if ( m_MoveToDislocation)
  278.       {
  279.         vector DestinationPoint = GetMeetingPlace() + vector(rand(-150, 150), rand(-150, 150), 0);
  280.         //Core_LogMessage("destination = " + DestinationPoint);
  281.         SetStartDelay( 0, 5000);
  282.         SetOrder_MoveTo( DestinationPoint, 30);
  283.         SetFireStyle_Nearest();
  284.       }
  285.       else
  286.       {
  287.         vector DestinationPoint = GetBattleAPlace() + vector(rand(-150, 150), rand(-150, 150), 0);
  288.         SetStartDelay( 0, 5000);
  289.         SetOrder_MoveTo( DestinationPoint, 30);
  290.         SetFireStyle_Nearest();
  291.       }
  292.     }
  293.     else
  294.     {
  295.       SetAttackStyle_DirectMove( true);
  296.       SetStartDelay( 0, 5000);
  297.       SetOrder_Attack( NearestEnemy, 30.0, 120.0, 30.0);
  298.       SetFireStyle_Enemy( NearestEnemy);
  299.     };
  300.   }
  301.  
  302.   void OnOrderedEnemyKilled()
  303.   {
  304.     SetFireStyle_Nearest();
  305.     DoAction();
  306.   }
  307.  
  308.   void OnEnemyTargeted()
  309.   {
  310.     if ( m_MoveToDislocation || m_Attack_A)
  311.     {
  312.       DoAction();
  313.     }
  314.   }
  315.  
  316.   void OnToDamage(
  317.     float   _DamageRate,
  318.     string  _TargetId,
  319.     string  _SourceType,
  320.     matrix  _SourcePlace)
  321.   {
  322.     if ( m_Wait)
  323.     {
  324.       Core_BroadcastEvent( "OnStartAttack_" + GetLocalBattleName());
  325.     }
  326.   }
  327. }
  328.  
  329. class CM9_Attack_Soviet extends CM9_Attack
  330. {
  331.   vector GetBattleAPlace() { return GetNavPoint( "NavPoint_Village_A"); }
  332.  
  333.   void OnStartAttack_A()
  334.   {
  335.     DelayedGiveOrder_Attack_A();
  336.   }
  337. }
  338.  
  339. class CM9_Attack_Nazi extends CM9_Attack
  340. {
  341.   vector GetBattleAPlace() { return GetNavPoint( "NavPoint_Village_A"); }
  342.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Village_A"); }
  343.  
  344.   void OnStartAttack_A()
  345.   {
  346.     DelayedGiveOrder_Attack_A();
  347.   }
  348.  
  349.   void DoAction()
  350.   {
  351.     string NearestEnemy = GetTargetedEnemy();
  352.  
  353.     if ( NearestEnemy == "")
  354.     {
  355.       if ( m_MoveToDislocation)
  356.       {
  357.         vector DestinationPoint = GetMeetingPlace() + vector(rand(-150, 150), rand(-150, 150), 0);
  358.         //Core_LogMessage("destination = " + DestinationPoint);
  359.         SetStartDelay( 0, 5000);
  360.         SetOrder_MoveTo( DestinationPoint, 30);
  361.         SetFireStyle_Nearest();
  362.       }
  363.       else
  364.       {
  365.         vector DestinationPoint = GetBattleAPlace() + vector(rand(-150, 150), rand(-150, 150), 0);
  366.         SetStartDelay( 0, 5000);
  367.         SetOrder_MoveTo( DestinationPoint, 30);
  368.         SetFireStyle_Nearest();
  369.       }
  370.     }
  371.     else
  372.     {
  373.       SetAttackStyle_DirectMove( true);
  374.       SetStartDelay( 0, 5000);
  375.       SetOrder_Attack( NearestEnemy, 30.0, 120.0, 30.0);
  376.       SetFireStyle_Enemy( NearestEnemy);
  377.     };
  378.   }
  379. }
  380.  
  381. class CM9_Soviet_A extends CM9_Attack_Soviet
  382. {
  383.   int GetActivateDelay() { return 50000; }
  384.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Village_A"); }
  385.   string GetLocalBattleName() { return "A"; }
  386. }
  387.  
  388. class CM9_Soviet_B extends CM9_Attack_Soviet
  389. {
  390.   int GetActivateDelay() { return 40000; }
  391.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Meeting_3"); }
  392.   vector GetLocalBattleName() { return "B"; }
  393.  
  394.   void OnStartAttack_B()
  395.   {
  396.     DelayedGiveOrder_MoveToDislocation();
  397.   }
  398. }
  399.  
  400. class CM9_Soviet_C extends CM9_Attack_Soviet
  401. {
  402.   int GetActivateDelay() { return 30000; }
  403.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Meeting_2"); }
  404.   vector GetLocalBattleName() { return "C"; }
  405.  
  406.   void OnStartAttack_C()
  407.   {
  408.     DelayedGiveOrder_MoveToDislocation();
  409.   }
  410. }
  411.  
  412. class CM9_Soviet_D extends CM9_Attack_Soviet
  413. {
  414.   int GetActivateDelay() { return 20000; }
  415.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Meeting_1"); }
  416.   vector GetLocalBattleName() { return "D"; }
  417.  
  418.   void OnStartAttack_D()
  419.   {
  420.     DelayedGiveOrder_MoveToDislocation();
  421.   }
  422. }
  423.  
  424. class CM9_Soviet_E extends CM9_Attack_Soviet
  425. {
  426.   int GetActivateDelay() { return 10000; }
  427.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Meeting_1"); }
  428.   vector GetLocalBattleName() { return "E"; }
  429.  
  430.   void OnStartAttack_E()
  431.   {
  432.     DelayedGiveOrder_MoveToDislocation();
  433.   }
  434. }
  435.  
  436. class CM9_Soviet_F extends CM9_Attack_Soviet
  437. {
  438.   int GetActivateDelay() { return 10000; }
  439.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Meeting_1"); }
  440.   vector GetLocalBattleName() { return "F"; }
  441.  
  442.   void OnStartAttack_F()
  443.   {
  444.     DelayedGiveOrder_MoveToDislocation();
  445.   }
  446. }
  447.  
  448. class CM9_Soviet_G extends CM9_Attack_Soviet
  449. {
  450.   int GetActivateDelay() { return 10000; }
  451.   vector GetMeetingPlace() { return GetNavPoint( "NavPoint_Meeting_2"); }
  452.   vector GetLocalBattleName() { return "G"; }
  453.  
  454.   void OnStartAttack_G()
  455.   {
  456.     DelayedGiveOrder_MoveToDislocation();
  457.   }
  458. }
  459.  
  460.  
  461. class CM9_Nazi_A extends CM9_Attack_Nazi
  462. {
  463.   int GetActivateDelay() { return 200000; }
  464.   vector GetLocalBattleName() { return "A"; }
  465.  
  466.   void DoAction()
  467.   {
  468.     string NearestEnemy = GetTargetedEnemy();
  469.  
  470.     if ( NearestEnemy == "")
  471.     {
  472.       NearestEnemy = GetNearestEnemyUnit_Ranged(500.0);
  473.     };
  474.  
  475.     if ( NearestEnemy == "")
  476.     {
  477.       // do nothing
  478.     }
  479.     else
  480.     {
  481.       SetAttackStyle_DirectMove( true);
  482.       SetStartDelay( 0, 5000);
  483.       SetOrder_Attack( NearestEnemy, 30.0, 120.0, 30.0);
  484.       SetFireStyle_Enemy( NearestEnemy);
  485.     };
  486.   }
  487. }
  488.  
  489. class CM9_Nazi_B extends CM9_Attack_Nazi
  490. {
  491.   int GetActivateDelay() { return 5*60000; }
  492.   vector GetLocalBattleName() { return "B"; }
  493.  
  494.   void OnStartAttack_B()
  495.   {
  496.     DelayedGiveOrder_MoveToDislocation();
  497.   }
  498. }
  499.  
  500. class CM9_Nazi_C extends CM9_Attack_Nazi
  501. {
  502.   int GetActivateDelay() { return 5*60000; }
  503.   vector GetLocalBattleName() { return "C"; }
  504.  
  505.   void OnStartAttack_C()
  506.   {
  507.     DelayedGiveOrder_MoveToDislocation();
  508.   }
  509. }
  510.  
  511. class CM9_Nazi_D extends CM9_Attack_Nazi
  512. {
  513.   int GetActivateDelay() { return 2*60000; }
  514.   vector GetLocalBattleName() { return "D"; }
  515.  
  516.   void OnStartAttack_D()
  517.   {
  518.     DelayedGiveOrder_MoveToDislocation();
  519.   }
  520. }
  521.  
  522. class CM9_Nazi_E extends CM9_Attack_Nazi
  523. {
  524.   int GetActivateDelay() { return 30000; }
  525.   vector GetLocalBattleName() { return "E"; }
  526.  
  527.   void OnStartAttack_E()
  528.   {
  529.     DelayedGiveOrder_MoveToDislocation();
  530.   }
  531. }
  532.  
  533. class CM9_Nazi_F extends CM9_Attack_Nazi
  534. {
  535.   int GetActivateDelay() { return 30000; }
  536.   vector GetLocalBattleName() { return "F"; }
  537.  
  538.   void OnStartAttack_F()
  539.   {
  540.     DelayedGiveOrder_MoveToDislocation();
  541.   }
  542. }
  543.  
  544. class CM9_Nazi_G extends CM9_Attack_Nazi
  545. {
  546.   int GetActivateDelay() { return 30000; }
  547.   vector GetLocalBattleName() { return "G"; }
  548.  
  549.   void OnStartAttack_G()
  550.   {
  551.     DelayedGiveOrder_MoveToDislocation();
  552.   }
  553. }
  554.  
  555.